<template>
  <div class="c-minh c-p" :class="[theme, loginStep >= 2 ? 'c-bg-f6' : 'c-bg-white']" :style="'--colorRGB:' + colorRGB">
    <div v-if="loginStep == 1">
      <div v-if="!isLogin || isFillUserInfo == 1" class="c-fs22 c-pv12 c-textAlign-c bind-head">请完善个人信息，以便向您提供更加优质的服务！</div>
      <div v-if="!isLogin" class="c-flex-column c-aligni-center c-ph24 c-mt80">
        <img :src="$addXossFilter(imgUrl, require('../../../assets/defult_head.png'))" class="c-block c-ww100 c-hh100 c-br4" />
        <div class="c-fs26 c-mt16">{{companyName}}</div>
      </div>
      <div v-else class="c-ph24 c-mt60 c-fc-xblack">
        <p class="c-fs36 c-fw600">验证码登录</p>
        <p class="c-fc-gray c-fs22 c-mt20">未注册的手机号码验证通过后将自动注册</p>
      </div>
      <div class="c-mt20 c-ph24">
        <div class="c-pv40 c-bd-b1-mgray c-flex-row c-aligni-center">
          <span class="c-ww184 c-fs26 c-bd-r1-d8 c-lh c-pl24">手机号<span v-if="!!isLogin">+86</span></span>
          <input type="tel" v-model="mobile" @focus='inputFocus' @blur='inputBlur' placeholder="请输入手机号" maxlength="13" class="c-pl30 c-fs24 c-fc-gray c-lh c-ml10 c-bd0 c-w90" />
        </div>
        <div class="c-pv40 c-bd-b1-mgray c-flex-row c-aligni-center">
          <span class="c-ww184 c-fs26 c-bd-r1-d8 c-lh c-pl24">验证码</span>
          <input @focus='inputFocus' @blur='inputBlur' v-model="code" name="" @input="code=code.slice(0, 4)" placeholder="请输入验证码" maxlength="4" class="c-pl30 c-fs24 c-fc-gray c-lh c-ml10 c-bd0 c-w50 needsclick" />
          <span class="c-fs24 theme-fc c-lh36 c-w40 c-block c-textAlign-c" @click="getYzcode">{{yzText}}</span>
        </div>
        <div class="c-pv40 c-bd-b1-mgray c-flex-row c-aligni-center" v-if="isNeedFillArea">
          <span class="c-ww150 c-fs26 c-bd-r1-d8 c-lh c-pl24">所在地<span class="c-fc-xxmred c-ml10 c-fs30">*</span></span>
          <div class="c-pl30 c-fs26 c-fc-gray c-lh c-flex-grow1 c-w0 c-flex-row c-aligni-center" id="maddr">
            <x-address :themeColor="$getThemeColor()" v-model="addrValue" @on-hide="saveAddress" title="" :list="addressData" placeholder="请选择地址" value-text-align="left" :show.sync="showAddress" class="c-fs26 c-fc-gray c-w80"></x-address>
            <span class="iconfont c-textAlign-r c-w20">&#xe635;</span>
          </div>
        </div>
        <block v-if="isFillUserInfo == 1">
          <div class="c-pv40 c-bd-b1-mgray c-flex-row c-aligni-center" v-for="(item,index) in customUserInfo" :key="index">
            <span class="c-ww184 c-fs26 c-bd-r1-d8 c-lh c-pl24">{{item.title}}<span v-if="item.require" class="c-fc-xxmred c-ml10 c-fs30">*</span></span>
            <input type="text" v-model="item.content" name="" :placeholder="'请输入'+item.title" id="" class="c-pl30 c-fs24 c-fc-gray c-lh c-ml10 c-bd0 c-w90" />
          </div>
        </block>
      </div>

      <div :class="!isLogin ? 'c-mt80' : 'c-mt60'" class="c-fc-white c-lh c-fs26 c-hh60 c-flex-row c-flex-center c-br40 theme-bg c-mh40" @click="submit">{{!!isLogin ? '登录' : '确定'}}</div>
      <section v-if="protocolInfo" class="c-pl24 c-pb20 c-flex-row c-flexw-wrap c-aligni-center c-justify-start c-lh38 c-fs20 theme-fc c-mt20" @click="changeCheckAgreement">
        <i v-show="!isCheckAgreement" class="iconfont c-fs20 c-fc-gray c-pr20">&#xe6f7;</i>
        <i v-show="isCheckAgreement" class="iconfont c-fs20 c-fc-gray c-pr20">&#xe6f2;</i>
        <span class="c-fc-gray">已阅读并同意</span>
        <template v-if="isAndroidApp || isiOSApp">
          <span @click.stop="linkToProtocol(protocolInfo.useProtocolUrl)">《用户服务协议》</span>
          <span @click.stop="linkToProtocol(protocolInfo.privacyProtocolUrl)">《隐私政策》</span>
        </template>
        <template v-else>
          <span @click.stop="clickProtocol(item)" v-for="(item, index) in protocolInfo" :key="index">《{{item.name}}》</span>
        </template>
      </section>
      <div class="c-pl24 c-pb20 c-flex-row c-flexw-wrap c-aligni-center c-justify-start c-lh38 c-fs20 c-fc-gray" v-if="isiOS && companyId == 'ldwk'">
        <i class="icon iconfont c-fs20 c-pr20" v-if="isAgree == 0" @click="isAgree = 1">&#xe692;</i>
        <i class="icon iconfont c-fs20 c-pr20" v-if="isAgree == 1" @click="isAgree = 0">&#xe6f2;</i>
        已阅读并同意 <span class="theme-fc" @click="goInfo(1)">用户协议</span>
      </div>

      <show-integrate :showIntegrate="showIntegrate" :integrateCount="integrateCount" v-if="showIntegrate" @closeShareInt="closeShareInt"></show-integrate>
      <cj-confirm :isShow="isShowImgCode" :option="{title:'图片验证码',titleCenter: true,showMasker: true,clickCloseModal: false,showCancelButton: true,cancelButtonText: '取消',confirmButtonText: '确认'}" @onConfirm="getYZCodeNext();" @onCancel="isShowImgCode = false;isClick = false;">
        <div class="c-ph40 c-mt20">
          <input type="number" v-model="imgCode" placeholder="请输入图片中验证码" class="c-w100 c-bg-sgray c-br8 c-fs22 c-pv12 c-ph24 c-bd0 needsclick" />
          <div class="c-flex-row c-aligni-center c-pt20 c-pb20">
            <img :src="codeImgInfo.img" @click="getImgCode()" class="c-ww160" alt=""/>
            <span class="c-ml20 c-fs22 c-fc-gray" @click="getImgCode()">看不清？换一张</span>
          </div>
        </div>
      </cj-confirm>
    </div>
    <div v-if="loginStep >= 2" class="c-pb120">
      <div v-if="loginStep == 2" class="c-bg-spink c-fc-orange c-fs22 c-fw400 c-ph24 c-pv16 c-lh36">
        提示：<span class="c-fw600">请选择一个账号作为主账号，</span>另一账号将会被注销.(被注销账号的余额、优惠券、课程等资产将迁移到保留账号，其他数据将会丢失)
      </div>
      <div class="c-ph24">
        <p class="c-fs24 c-fw600 c-fc-xblack c-pt40">当前帐号</p>
        <div v-if="currentUserIndex > -1" class="c-mt20 c-bg-white c-ph24 c-pv24 c-br10 c-flex-row c-justify-sb c-aligni-center">
          <div class="c-flex-grow1 c-flex-row c-justify-sb ">
            <div class="c-p c-ww92 c-hh92 c-brp50 c-flex-shrink0">
              <div class="c-pa c-p-b0 c-p-r0 c-flex-row c-aligni-center c-pz10">
                <div style="z-index: -1" v-if="checkIncludeWechat(userInfo[currentUserIndex].fromChannel)" :class="checkIncludeMobile(userInfo[currentUserIndex].fromChannel) ? 'c-mrm16' : ''" class="c-flex-shrink0 c-flex-row c-flex-center">
                  <img src="@/assets/i/wap/common/wechat-icon.png" alt="" class="c-ww30 c-hh30 c-brp50">
                </div>
                <div v-if="checkIncludeMobile(userInfo[currentUserIndex].fromChannel)" class="c-flex-shrink0 c-flex-row c-flex-center">
                  <img src="@/assets/i/wap/common/mobile-icon.png" alt="" class="c-ww30 c-hh30 c-brp50">
                </div>
              </div>
              <img class="c-ww92 c-hh92 c-brp50" :src="$addXossFilter(userInfo[currentUserIndex].headimgurl, require('../../../assets/defult_head.png'))" alt="">
            </div>
            <div class="c-flex-grow1 c-ph20 c-w0 c-fw400">
              <div class="c-fs28 c-fc-xblack c-text-ellipsis1 c-flex-row c-aligni-center">
                <div class="c-text-ellipsis1">{{userInfo[currentUserIndex].nickname}}</div>
                <identity-com class="c-pl10" :isShowOrdinary="false" :vipType="userInfo[currentUserIndex].vipType"></identity-com>
              </div>
              <div class="c-fs22 c-fc-gray">
                <div class="c-mt10">已购课程：{{userInfo[currentUserIndex].courseNum}} | 优惠券：{{userInfo[currentUserIndex].couponNum}}</div>
                <div class="c-mt10 c-flex-row c-aligni-center">余额：{{Number(userInfo[currentUserIndex].balance || 0).toFixed(2)}}</div>
                <div class="c-mt10">{{customPointName}}：{{userInfo[currentUserIndex].points}}</div>
                <div class="c-mt10">虚拟币：{{userInfo[currentUserIndex].coinAmount}}</div>
              </div>
            </div>
          </div>
          <div v-if="loginStep == 2" @click="selectUser(currentUserIndex)" class="iconfont c-fs32 c-ww32 c-flex-shrink0" :class="selectIndex == currentUserIndex ? 'theme-fc' : 'c-fc-sgray'">{{ selectIndex == currentUserIndex ? '&#xe6f6;' : '&#xe6f7;'}}</div>
        </div>
        <p class="c-fs24 c-fw600 c-fc-xblack c-mt40">冲突帐号</p>
        <div v-for="(item, index) in userInfo" v-if="index != currentUserIndex" :key="index" class="c-mt20 c-bg-white c-ph24 c-pv24 c-br10 c-flex-row c-justify-sb c-aligni-center">
          <div class="c-flex-grow1 c-flex-row c-justify-sb ">
            <div class="c-p c-ww92 c-hh92 c-brp50 c-flex-shrink0">
              <div class="c-pa c-p-b0 c-p-r0 c-flex-row c-aligni-center c-pz10">
                <div style="z-index: -1" v-if="checkIncludeWechat(item.fromChannel)" :class="checkIncludeMobile(item.fromChannel) ? 'c-mrm16' : ''" class="c-flex-shrink0 c-flex-row c-flex-center">
                  <img src="@/assets/i/wap/common/wechat-icon.png" alt="" class="c-ww30 c-hh30 c-brp50">
                </div>
                <div v-if="checkIncludeMobile(item.fromChannel)" class="c-flex-shrink0 c-flex-row c-flex-center">
                  <img src="@/assets/i/wap/common/mobile-icon.png" alt="" class="c-ww30 c-hh30 c-brp50">
                </div>
              </div>
              <img class="c-ww92 c-hh92 c-brp50" :src="$addXossFilter(item.headimgurl, require('../../../assets/defult_head.png'))" alt="">
            </div>
            <div class="c-flex-grow1 c-ph20 c-w0 c-fw400">
              <div class="c-fs28 c-fc-xblack c-text-ellipsis1 c-flex-row c-aligni-center">
                <div class="c-text-ellipsis1">{{item.nickname}}</div>
                <identity-com :isShowOrdinary="false" :vipType="item.vipType"></identity-com>
                <div v-if="loginStep == 3" class="c-ml10 c-flex-row c-flex-center c-ww96 c-hh28 destroy-icon c-fs18">即将销毁</div>
              </div>
              <div class="c-fs22 c-fc-gray">
                <div class="c-mt10">已购课程：{{item.courseNum}} | 优惠券：{{item.couponNum}}</div>
                <div class="c-mt10">余额：{{Number(item.balance || 0).toFixed(2)}}</div>
                <div class="c-mt10">{{customPointName}}：{{item.points}}</div>
                <div class="c-mt10">虚拟币：{{item.coinAmount}}</div>
                <div class="c-mt10">手机号：{{item.mobile}}</div>
              </div>
            </div>
          </div>
          <div v-if="loginStep == 2" @click="selectUser(index)" class="iconfont c-fs32 c-fc-sgray c-ww32 c-flex-shrink0" :class="selectIndex == index ? 'theme-fc' : 'c-fc-sgray'">{{selectIndex == index ? '&#xe6f6;' : '&#xe6f7;'}}</div>
        </div>
        <div v-if="loginStep == 3">
          <div class="c-fs22 c-fc-xblack c-mt40 c-lh36">
            <!-- 目前只会出现最多2个账号的情况 -->
            将<span class="c-fw600" v-for="(nItem, nIndex) in userInfo" v-if="currentUserIndex != nIndex" :key="nIndex">{{nItem.nickname}}{{userInfo.length > 2 && (nIndex + 1) < userInfo.length ? '、' : ''}}</span>以下数据迁移到<span class="c-fw600">{{userInfo[currentUserIndex].nickname}}</span>
          </div>
          <div class="c-fs22 c-fc-gray c-mt10">余额、已购课程、优惠券、虚拟币、{{customPointName}}。</div>
          <div class="c-fs22 c-fc-xblack c-mt40 c-lh36">
            <span class="c-fw600" v-for="(nItem, nIndex) in userInfo" v-if="currentUserIndex != nIndex" :key="nIndex">{{nItem.nickname}}{{userInfo.length > 2 && (nIndex + 1) < userInfo.length ? '、' : ''}}</span>的其他数据将永远丢失无法找回，包含但不限于：
          </div>
          <div class="c-fs22 c-fc-gray c-mt10">课程学习进度、身份、客户关系、收藏记录等</div>
        </div>
      </div>
      <div class="c-pf c-p-b0 c-bg-white c-w100 c-hh100 c-ph24 c-flex-row c-justify-sb c-aligni-center c-pz100 c-maxw640">
        <div class="c-flex-row c-flex-center c-fs28 c-fc-xblack c-bd1-mgray c-ww282 c-hh72 c-br40" @click="exitMerge">退出合并</div>
        <div class="c-flex-row c-flex-center c-fs28 c-fc-white theme-bg c-ww286 c-hh70 c-br40" @click="goStep()">{{loginStep == 3 ? '确认合并' : '下一步'}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { XAddress } from 'ckjrweb-mp-ui/src/components/index';
import { utilJs } from "@/utils/common.js";
import showIntegrate from "@/components/templates/common/showIntegrate.vue";
import CjConfirm from "@/plugin/cjConfirm/cjConfirm.vue";
import identityCom from "@/components/templates/common/identityCom.vue";
let isRetrieve = 0;
let inputScrollTop = 0;
const THEME_RGB_MAP = global.THEME_RGB_MAP;
export default {
  name: "BindMobile",
  components: {
    XAddress,
    showIntegrate,
    CjConfirm,
    identityCom
  },
  props: [],
  beforeCreate() { },
  data() {
    return {
      companyAuth: null,
      themeColor: localStorage.getItem("colorName") || 'mb5_default',
      showAddress: false,
      addrValue: [],
      addressData: '', // addressData,
      theme: localStorage.getItem("colorName")
        ? localStorage.getItem("colorName")
        : "mb5_default",
      imgUrl: window.localStorage.getItem("shareLogo"),
      companyName: window.localStorage.getItem("companyName"),
      companyId: window.localStorage.getItem("companyId"),
      num: 60,
      interval: null,
      yzText: "获取验证码",
      isYz: true,
      mobile: null,
      code: null, // 验证码
      isClick: false,
      isSubmit: true, //防止多次提交
      isAgree: 1, //ios app同意条款
      isiOS: false,
      customUserInfo: [],
      isFillUserInfo: 0,
      enableAreaAgent: 0,
      enableXhAreaAgent: 0,
      codeImgInfo: '', //图形验证码信息
      imgCode: '', //填入的图形验证码
      integrateCount: 0, //绑定手机获取积分
      showIntegrate: false,
      ckFrom: global.ckFrom,
      isCheckAgreement: false,
      isLogin: 0, // 是否是作为手机登录页面
      loginStep: 1, // 登录步骤 1 登录页面 2 选择合并账号
      userCount: 0, // 当前登录手机号绑定的平台账号数量
      userInfo: [], // 当前手机号的所有账号信息
      constUserInfo: [], // 原始数据
      constUserIndex: -1, // 最开始选中的当前账号
      currentUserIndex: 0, // 当前账号信息在userInfo中的索引（比如抖音打开就是对应抖音的账号信息索引）
      fromChannel: -1, // 当前浏览器 -1=未知; 1=mp 公众号; 2=wxapp 小程序; 3=android; 4=ios; 5=web/pc; 13 其他手机浏览器; 14=抖音
      selectIndex: 0, // 选中的用户
      destroyIndex: [], // 即将销毁的用户index
      isClickCode: false, // 是否已经点击获取验证码，现在获取绑定该手机号的账户信息都需要走获取验证码这步，所以需要保证用户点击过验证码
      isAllWechat: false, // 是否绑定账号都是微信
      refereeId: '', // 绑定关系
      protocolInfo: null,
      isAndroidAp: false,
      isiOSApp: false,
      enableWriteAddress: 0, // 绑定手机时是否填写所在地
      isShowImgCode: false, //是否展示图形验证码
      customPointName: localStorage.getItem("customPointName"),
      errorType: 1
    };
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() { },
  computed: {
    colorRGB() {
      let rgbStr = this.tabColorRGB ? this.tabColorRGB : THEME_RGB_MAP[this.themeColor];
      return rgbStr;
    },
    isNeedFillArea() { // 是否需要必填用户地区（旧版和新版区域代理都需要）, personalTailorByGldg私人订制,enableShareholderAreaAgent股东区域代理必填地区 || (9.29新增)绑定手机时填写所在地 0否 1是
      let locateTypeTmp = localStorage.getItem("locateType");
      // return (this.enableAreaAgent == 1 || (this.companyAuth && this.companyAuth.enableNewAreaAgent == 1) || this.enableXhAreaAgent == 1 || this.$route.query.personalTailorByGldg == 1 || (this.companyAuth && this.companyAuth.enableShareholderAreaAgent == 1)) || (this.isFillUserInfo == 1 && this.enableWriteAddress == 1)
      return locateTypeTmp == 1 || locateTypeTmp == 2
    },
  },
  watch: {
    mobile() {
      if (this.mobile && isNaN(this.mobile)) {
        this.mobile = "";
      } else if (this.mobile) {
        this.mobile.length > 11 && this.mobile.substr(0, 11);
      }
    }
  },
  beforeRouteLeave(to, from, next) {
    if (from.path == "/homePage/login/bindMobile" && this.loginStep > 1) {
      this.loginStep--;
      this.userInfo = JSON.parse(JSON.stringify(this.constUserInfo))
      this.currentUserIndex = JSON.parse(JSON.stringify(this.constUserIndex))
      next(false);
    } else {
      next(true);
    }
  },
  methods: {
    // 手机号登录
    checkSendCode() {
      let companyId = utilJs.getCompanyIdByHerf();
      let data = {
        'mobile': this.mobile,
        'verifyCode': this.code,
        'fromApp': this.fromChannel == 14 ? 'dy' : 'qt',
        'companyId': companyId
      }
      utilJs.postMethod(global.apiurl + "accountConnect/checkSendCode", data, res => {
        this.goStep()
      })
    },
    checkIncludeWechat(fromChannel) { // fromChannel 是否包含手机浏览器
      if (fromChannel && (fromChannel.includes('1') || fromChannel.includes('2'))) {
        return true
      } else {
        return false
      }
    },
    checkIncludeMobile(fromChannel) { // fromChannel 是否包含手机浏览器
      if (fromChannel && (fromChannel.includes('13') || fromChannel.includes('14'))) {
        return true
      } else {
        return false
      }
    },
    // 手机号登录
    mobileLogin(userId) {
      let companyId = utilJs.getCompanyIdByHerf();
      let url = "accountConnect/mobileLogin";
      let data = {
        'mobile': this.mobile,
        'verifyCode': this.code,
        'fromApp': this.fromChannel == 14 ? 'dy' : 'qt',
        'companyId': companyId
      }
      if (!!this.refereeId) { // 关系绑定
        data.refereeId = this.refereeId;
      }
      if (!!userId) { // 选择账号登陆
        data.userId = userId;
      }
      if (!this.userCount) { // 注册
        data.customUserInfo = this.isFillUserInfo == 1 ? this.customUserInfo : null;
        let address = {};
        if (this.isNeedFillArea) { // 必填用户所在地
          let provinceId = this.addrValue[0];
          let cityId = this.addrValue[1];
          let areaId = this.addrValue[2];
          address = { 'provinceId': provinceId, 'cityId': cityId, 'areaId': areaId };
          data.address = address;
        }
      }
      if (this.userCount > 1 && !userId) { // 账号合并
        data.userId = this.userInfo[this.currentUserIndex].userId;
        let cancelUserId = []
        this.destroyIndex.forEach(item => {
          cancelUserId.push(this.userInfo[item].userId)
        });
        data.cancelUserId = cancelUserId;
        url = "accountConnect/accountCombine"
      }
      utilJs.postMethod(global.apiurl + url, data, res => {
        if (res.t != "" && res.u != "" && res.c != null) {
          this.beforeLogin(res, userId);
        }
      }, failRes => {
        this.clearData()
      })
    },
    beforeLogin(res, userId = '') {
      window.localStorage.removeItem("isVisitor");
      window.localStorage.setItem("companyId", res.c);
      window.localStorage.setItem(res.c, res.c);
      window.localStorage.setItem("userId", res.u);
      window.localStorage.setItem("token", res.t);
      window.localStorage.setItem(localStorage.getItem("companyId") + "|token", res.t);
      let timer = null;
       // 手机号登录 && （非合并流程即注册和直接登录 || 账号均为微信来源，合并过程直接选择一个账号登录）的情况下，无需提示合并成功，直接登录进去
      if (!!this.isLogin && (this.loginStep == 1 || !!userId)) {
        timer = setTimeout(() => {
          clearTimeout(timer)
          window.location.reload();
        }, 300)
        this.goBack(res)
      } else {
        let $this = this;
        this.$showCjToast({
          text: "合并成功",
          type: "success",
        }).then(() => {
          $this.loginStep = 1
          if (!!$this.isLogin) {
            timer = setTimeout(() => {
              clearTimeout(timer)
              window.location.reload();
            }, 300)
            $this.goBack(res)
          } else {
            $this.goBack(res)
          }
        });
      }
    },
    setSingle(arr) { // 去重
      if (!arr || !arr.length) {
        return []
      }
      let map = new Map();
      for (let item of arr) {
        if (!map.has(item.userId)) {
          map.set(item.userId, item);
        };
      };
      return [...map.values()];
    },
    //获取当前要绑定的手机号所有的账户信息
    getCustomerUserInfo() {
      if (!this.mobile) {
        return
      }
      utilJs.getMethod(`${global.apiurl}common/getCustomerUserInfo?companyId=${this.companyId}&mobile=${this.mobile}`, res => {
        this.userInfo = [...res.currentUserInfo, ...res.userInfo];
        this.userInfo = this.setSingle(this.userInfo); // 去重，防止接口返回重复数据，接口有做了判断，让前端也加
        this.constUserInfo = JSON.parse(JSON.stringify(this.userInfo))
        this.userCount = this.userInfo.length;
        this.currentUserIndex = 0;
        this.selectIndex = 0;
        this.constUserIndex = 0;
      });
    },
    selectUser(index) {
      this.selectIndex = index
    },
    goStep() {
      if (this.loginStep == 2) {
        this.destroyIndex = [];
        this.currentUserIndex = this.selectIndex; // 最后确认是否合并，当前账号更改为选中账号，在提示用户一遍
        for (let i = 0; i < this.userInfo.length; i++) {
          // 有出现过主账号id和待废弃的id一致，合并后直接把账号删除的情况，所以需要多加一个主账号id和待废弃id不一致的判断
          if (i != this.currentUserIndex && this.userInfo[this.currentUserIndex].userId != this.userInfo[i].userId) {
            let currentData = JSON.parse(JSON.stringify(this.userInfo[this.currentUserIndex]));
            this.userInfo[this.currentUserIndex] = {
              userId: currentData.userId,
              fromChannel: [...currentData.fromChannel, ...this.userInfo[i].fromChannel],
              headimgurl: currentData.headimgurl,
              mobile: currentData.mobile,
              nickname: currentData.nickname,
              vipType: currentData.vipType,
              vipName: currentData.vipName,
              balance: Number(currentData.balance) + Number(this.userInfo[i].balance),
              couponNum: Number(currentData.couponNum) + Number(this.userInfo[i].couponNum),
              courseNum: Number(currentData.courseNum) + Number(this.userInfo[i].courseNum),
              points: Number(currentData.points) + Number(this.userInfo[i].points),
              coinAmount: Number(currentData.coinAmount) + Number(this.userInfo[i].coinAmount)
            };
            this.userInfo[i] = {
              userId: this.userInfo[i].userId,
              fromChannel: [],
              headimgurl: this.userInfo[i].headimgurl,
              mobile: this.userInfo[i].mobile || '',
              nickname: this.userInfo[i].nickname,
              vipType: 0,
              vipName: '',
              balance: 0,
              couponNum: 0,
              courseNum: 0,
              points: 0,
              coinAmount: 0
            }
            this.destroyIndex.push(i);
          }
        }
      }
      if (this.loginStep < 3) {
        this.loginStep++;
      } else {
        let nicknameStr = '';
        this.destroyIndex.forEach((item, index) => {
          nicknameStr = nicknameStr + `【${this.userInfo[item].nickname}】`;
        })
        this.$cjConfirm({
          title: '提示',
          message: `确定要将${nicknameStr}的数据迁移到【${this.userInfo[this.currentUserIndex].nickname}】吗?`,
          onConfirm:() => {
            if (!!this.isLogin) { // 如果是登录就直接合并
              this.mobileLogin();
            } else { // 绑定手机就是先绑手机在走合并
              this.submit()
            }
          }
        })
      }
    },
    exitMerge() {
      if (!!this.isLogin && this.isAllWechat) { // 手机号登录并且手机绑定的账号来源都是微信，可以选择账号登录
        this.$cjConfirm({
          title: '提示',
          message: `您当前手机号下有多个账号，退出合并需选择一个账号作为登入账号，是否确认当前【${this.userInfo[this.selectIndex].nickname}】账号作为登入账号？`,
          onConfirm:() => {
            this.mobileLogin(this.userInfo[this.selectIndex].userId);
          },
          onCancel:() => {
            this.clearData();
          }
        })
      } else {
        this.clearData()
      }
    },
    clearData() {
      this.isClick = false;
      this.isSubmit = true;
      this.isAgree = 1;
      this.codeImgInfo = '';
      this.imgCode = '';
      this.loginStep = 1;
      this.userCount = 0;
      this.userInfo = [];
      this.constUserInfo = [];
      this.currentUserIndex = 0;
      this.constUserIndex = 0;
      this.selectIndex = 0;
      this.destroyIndex = [];
      this.isClickCode = false;
      this.isAllWechat = false;
      this.isCheckAgreement = false;
      this.mobile = null;
      this.code = null;
      clearInterval(this.interval);
      this.yzText = "获取验证码";
      this.isYz = true;
      this.num = 60;
      if (!this.isLogin) {
        this.getAreaListForAgent()
      }
    },
    loginSendCode() {
      let companyId = utilJs.getCompanyIdByHerf();
      let data = {
        mobile: this.mobile,
        companyId: companyId,
        fromApp: this.fromChannel == 14 ? 'dy' : 'qt'
      }
      utilJs.postMethod(global.apiurl + "common/loginSendCode", data, res => {
        this.userCount = res.userInfo ? res.userInfo.length : 0;
        this.userInfo = res.userInfo || [];
        this.userInfo = this.setSingle(this.userInfo);
        this.constUserInfo = JSON.parse(JSON.stringify(this.userInfo))
        this.currentUserIndex = -1;
        this.constUserIndex = -1;
        this.selectIndex = '';
        if (this.userCount > 1) { // 账号数量大于一个，走账号合并流程
          let tmpIndex = -1;
          let formWechatCount = 0; // 账号来源为微信的有几个
          for (let i = 0; i < this.userInfo.length; i++) {
            let fromChannel = this.userInfo[i].fromChannel || [];
            if (this.currentUserIndex == -1 && fromChannel.includes(this.fromChannel)) {
              this.currentUserIndex = i;
            }
            // 把第一个是手机浏览器注册的账号找出来
            if (tmpIndex == -1 && this.checkIncludeMobile(fromChannel)) {
              tmpIndex = i
            }
            if (fromChannel.length == 1 && this.checkIncludeWechat(fromChannel)) {
              formWechatCount++
            }
          }
          this.isAllWechat = formWechatCount == this.userCount ? true : false;
          // 若是所有用户来源都没有与当前相匹配的，则取第一个是手机浏览器注册的账号，都没有那就默认第一个作为当前账号
          this.currentUserIndex = this.currentUserIndex == -1 ? (tmpIndex == -1 ? 0 : tmpIndex) : this.currentUserIndex;
          this.selectIndex = this.currentUserIndex;
          this.constUserIndex = this.currentUserIndex;
        } else if (this.userCount == 0) { // 该手机下没有账号，则需要走新建账号流程，还需要添加后台设置的绑定手机号信息
          this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
          this.customUserInfo = res.customerUserInfo || [];
          this.isFillUserInfo = this.customUserInfo && this.customUserInfo.length > 0 ? 1 : 0;
          this.enableAreaAgent = !!res.enableAreaAgent ? 1 : 0;
          this.getAreaListForAgent()
        }
        this.interval = setInterval(this.getYzMethod, 1000);
      }, failRes => {
        clearInterval(this.interval);
        this.yzText = "获取验证码";
        this.isYz = true;
        this.num = 60;
        this.isClick = false;
      })
    },
    //绑定手机领取积分
    bindGetIntegration() {
      if (this.companyAuth.enableBindPhonePoint != 1) {
        return;
      }
      let $this = this;
      //积分来源 1. 分享视频，2：观看视频，3：分享音频，4：观看音频，14：分享文章 51：分享知识套餐 52：分享专刊 53：分享直播 54：观看直播 55：绑定手机
      let data = {
        cId: -1,
        extId: -1,
        pointFrom: 55,
        duration: -1
      };
      utilJs.postMethod(`${global.apiurl}common/getPoints`, data, function (res) {
        let integrateCount = res.points;
        if (integrateCount > 0) {
          $this.integrateCount = integrateCount;
          $this.showIntegrate = true;
        }
      });
    },
    closeShareInt() {
      this.showIntegrate = false;
    },
    saveAddress(closeType) {
      if (closeType && this.addrValue.length == 0) {
        this.$showCjToast({
          text: "请选择地址",
          type: 'warn',
          time: 3000
        });
      }
    },
    getImgCode() {
      let $this = this;
      if ($this.isLoading == true) {
        return;
      }
      $this.isLoading = true;
      utilJs.getMethod(`${global.apiurl}common/captcha`, res => {
        $this.codeImgInfo = res;
        $this.isLoading = false;
      }, failRes => {
        $this.isLoading = false;
      });
    },
    //IOS微信6.7以上版本会导致输入法收起的时候，键盘没收起，需要手动滚下屏幕
    inputFocus() {
      if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        inputScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
      }
    },
    inputBlur() {
      if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        setTimeout(() => {
          document.body.scrollTop = inputScrollTop - 1 || 0;
        });
      }
    },
    changeCheckAgreement() {
      this.isCheckAgreement = !this.isCheckAgreement;
      this.isAgree = this.isCheckAgreement ? 1 : 0;
    },
    clickProtocol(item) {
      this.$routerGo(this, "push", { path: `/homePage/agent/protocolInfo`, query: { protocolId: item.protocolId } });
    },
    goInfo(index) {
      this.$routerGo(this, "push", { path: '/homePage/agent/agentInfo', query: { index: index } });
    },
    getYzMethod: function () {
      this.isYz = false;
      this.num -= 1;
      this.yzText = this.num + "秒后重新获取";
      if (this.num == 0) {
        clearInterval(this.interval);
        this.yzText = "获取验证码";
        this.isYz = true;
        this.num = 60;
        this.isClick = false;
      }
    },
    sendCode() {
      if (this.imgCode == '') {
        this.$showCjToast({
          text: "图片验证码不能为空",
          type: "warn",
          isShowMask: "true"
        });
        this.isClick = false;
        return;
      }
      this.yzText = "发送中";
      let $this = this;
      utilJs.postMethod(global.apiurl + "members/sendCode", {
        mobile: this.mobile,
        isBindMobile: isRetrieve != 1,
        captcha: this.imgCode,
        captchaKey: this.codeImgInfo.key,
      }, res => {
        if (res.errMsg) {
          $this.yzText = "获取验证码";
          $this.isClick = false;
          $this.$showCjToast({
            text: res.errMsg,
            type: "warn",
          });
        } else {
          $this.interval = setInterval($this.getYzMethod, 1000);
        }
      }, function () {
        clearInterval($this.interval);
        $this.yzText = "获取验证码";
        $this.isYz = true;
        $this.num = 60;
        $this.isClick = false;
      })
    },
    getYzcode: function () {
      if (this.isClick) {
        return;
      }
      this.isClick = true;
      if (!this.mobile) {
        this.$showCjToast({
          text: "手机号不能为空",
          type: "warn",
        });
        this.isClick = false;
        return
      }
      this.isClickCode = true;
      if (!!this.isLogin) {
        this.loginSendCode();
      } else {
        this.getImgCode();
        this.isShowImgCode = true;
      }
    },
    //获取费登录模式下验证码
    getYZCodeNext() {
      if (this.imgCode == '') {
        this.$showCjToast({
          text: "图片验证码不能为空",
          type: "warn",
        });
        return;
      }
      this.isShowImgCode = false;
      this.sendCode();
      if (!isRetrieve) { // 优先走账号平移流程，这边就不需要获取该手机下绑定的账号信息，无论账号几个都先走平移账号流程
        this.getCustomerUserInfo(); // 同时获取该手机是否绑定过账号，以及所有绑定过的账号信息
      }
    },
    //检测提交
    checkSubmit() {
      let msg = '';
      if (this.isiOS && localStorage.getItem("companyId") == "ldwk" && this.isAgree == 0) { //ldwk:百家青少年教育app
        msg = "登陆注册同意用户协议";
      }
      if (!msg && !this.isCheckAgreement && this.protocolInfo) {
        msg = "请先同意相关协议！"
      }
      let toastTitle = '';
      if (this.isFillUserInfo == 1 && this.customUserInfo) {
        for (var i = 0; i < this.customUserInfo.length; i++) {
          if (this.customUserInfo[i].require && this.customUserInfo[i].content == "") {
            toastTitle = this.customUserInfo[i].title;
            this.errorType = 1;
            break;
          }
          if ((this.customUserInfo[i].type == 2 || this.customUserInfo[i].type == 3) && this.customUserInfo[i].content.length > 20) {
            toastTitle = this.customUserInfo[i].title;
            this.errorType = 2;
            break;
          }
        }
      }
      // 判断手机号、验证码、必填所在地、必填信息是否都填了
      if (!msg && (!this.mobile || !this.isClickCode || !this.code || (this.isNeedFillArea && this.addrValue.length == 0) || !!toastTitle)) {
        msg = !this.mobile ? "手机号不能为空" : !this.isClickCode ? "请先获取验证码" : !this.code ? "验证码不能为空" : (this.isNeedFillArea && this.addrValue.length == 0) ? "请选择所在地" : (this.errorType == 1 ? `请填写${toastTitle}` : `${toastTitle}不能超过20个字符`)
      }
      if (!!msg) {
        this.$showCjToast({
          text: msg,
          type: "warn",
        });
        return false;
      } else {
        return true;
      }
    },
    submit: function () {
      if (!this.checkSubmit()) {
        return;
      }
      if (this.loginStep == 1 && this.userCount > 1) { // 绑定该手机的账号数大于1个，要走合并账号流程
        this.checkSendCode()
        return
      } else if (this.loginStep == 1 && !!this.isLogin) {
        // 作为登录页，小于等于一个直接登录
        this.mobileLogin()
        return
      }
      if (!this.isSubmit) {
        return;
      }
      this.isSubmit = false;
      let memberData = {
        'mobile': this.mobile,
        'code': this.code,
        'customUserInfo': this.isFillUserInfo == 1 ? this.customUserInfo : null,
      }
      let address = {};
      if (this.isNeedFillArea) { // 必填用户所在地
        let provinceId = this.addrValue[0];
        let cityId = this.addrValue[1];
        let areaId = this.addrValue[2];
        address = { 'provinceId': provinceId, 'cityId': cityId, 'areaId': areaId };
        memberData.address = address;
      }
      if (isRetrieve == 1) {
        this.retrieveAccount(memberData);
      } else {
        this.bindMobile(memberData);
      }
    },
    goBack(res) {
      let that = this;
      if (that.$route.query.goVip) {
        that.$routerGo(that, "replace", { path: "/member/vip/vipUp" });
      } else if (!that.isLogin && that.$route.query.isGoPay && (that.$route.query.isGoPay + '' == 'true' || that.$route.query.isGoPay + '' == '1')) {
        // 非登录时才返回支付页（防止登录后该产品已有权限）
        let ckFrom = that.$route.query.ckFrom;
        let extId = that.$route.query.extId;
        let cId = that.$route.query.cId;
        let isFromInvite = that.$route.query.isFromInvite;

        if (ckFrom == global.ckFrom.flashSalesCourse || ckFrom == global.ckFrom.flashSalesColumn) {
          let goPathQuery = {
            cId: cId,
            extId: extId,
            pId: that.$route.query.pId,
            ckFrom: ckFrom,
            isFromInvite: isFromInvite,
            recRelateId: that.$route.query.recRelateId,
            recType: that.$route.query.recType
          };
          if (that.goodsRoomId) {
            goPathQuery.goodsRoomId = that.goodsRoomId;
          }
          if (that.$route.query.courseType) {
            goPathQuery.courseType = that.$route.query.courseType;
          }
          that.$routerGo(that, "replace", { path: "/homePage/course/coursePay", query: goPathQuery });
        } else {
          let goPathQuery = {
            cId: cId,
            extId: extId,
            ckFrom: ckFrom,
            isFromInvite: isFromInvite,
            recRelateId: that.$route.query.recRelateId,
            recType: that.$route.query.recType
          };
          if (that.$route.query.prodId) {
            goPathQuery.prodId = that.$route.query.prodId;
          }
          if (that.goodsRoomId) {
            goPathQuery.goodsRoomId = that.goodsRoomId;
          }
          if (that.$route.query.courseType) {
            goPathQuery.courseType = that.$route.query.courseType;
          }
          if (that.$route.query.stepIndex) { //阶梯拼团
            goPathQuery.stepIndex = that.$route.query.stepIndex;
          }
          that.$routerGo(that, "replace", { path: "/homePage/course/coursePay", query: goPathQuery });
        }
      } else if (that.$route.query.isGoHome == 1) {
        if (res.msg && res.msg == "未找到该用户") {
          if ((navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1) && window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger' && localStorage.getItem("companyId")) {
            // 把之前的cookie设置过期，防止cookie不停地增加导致http request 400错误
            let exp = new Date();
            exp.setTime(exp.getTime() - 1);
            document.cookie = localStorage.getItem("companyId") + "|token=;expires=" + exp.toGMTString() + ";path=/";
          }
          localStorage.clear();
          window.location.href = window.location.href.split("#")[0] + "#/"
        } else {
          that.$routerGo(that, "replace", { path: "/" });
        }
      } else if (that.$route.query.isQa == 1) {
        that.$routerGo(that, "replace", {
          path: "/homePage/course/coursePay",
          query: {
            extId: that.$route.query.questionOrderId,
            ckFrom: that.$route.query.ckFrom,
            cId: -1
          }
        });
      } else if (that.$route.query.recRelateId) { //relateId推荐有礼-推荐人id
        let route = {
          path: "/member/recommend/recommendIndex", //分享页为推荐有礼页
          query: {
            recRelateId: that.$route.query.recRelateId,
            recType: that.$route.query.recType,
            bindPhone: 1
          }
        };
        if (that.$route.query.goHomeIndex) { //分享页为首页
          route = {
            path: "/",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.goVipUp) { //分享页为会员升级页
          route = {
            path: "/member/vip/vipUp",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.goColumn) { //分享页为专栏详情页
          route = {
            path: "/homePage/column/columnDetail",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              cId: that.$route.query.cId,
              extId: that.$route.query.extId,
              ckFrom: that.$route.query.ckFrom,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.goImgText) { //分享页为图文详情页
          route = {
            path: "/homePage/course/imgText",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              courseId: that.$route.query.courseId,
              extId: that.$route.query.extId,
              ckFrom: that.$route.query.ckFrom,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.goVoice) { //分享页为音频详情页
          route = {
            path: "/homePage/course/voice",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              courseId: that.$route.query.courseId,
              extId: that.$route.query.extId,
              ckFrom: that.$route.query.ckFrom,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.goVideo) { //分享页为视频详情页
          route = {
            path: "/homePage/course/video",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              courseId: that.$route.query.courseId,
              extId: that.$route.query.extId,
              ckFrom: that.$route.query.ckFrom,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.ckFrom == that.ckFrom.activity) { // 分享页为活动详情页
          route = {
            path: "/activity/activityDetail",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              ActivityNo: that.$route.query.activityId,
              ckFrom: that.ckFrom.activity,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.ckFrom == that.ckFrom.live) { // 分享页为活动详情页
          route = {
            path: "/homePage/live/liveDetail",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              liveId: that.$route.query.liveId,
              ckFrom: that.ckFrom.live,
              bindPhone: 1,
            }
          }
        }
        if (that.$route.query.ckFrom == that.ckFrom.camp) { // 分享页为训练营详情页
          route = {
            path: "/homePage/camp/campDetail",
            query: {
              recRelateId: that.$route.query.recRelateId,
              recType: that.$route.query.recType,
              campId: that.$route.query.campId,
              ckFrom: that.ckFrom.camp,
              bindPhone: 1,
            }
          }
        }
        that.$routerGo(that, "replace", route);
      } else {
        let pp = that.$route.query.prevPath ? that.$route.query.prevPath : null;
        if (pp && !pp.includes('homePage/login/bindMobile')) {
          that.$routerGo(that, "replace", { path: pp });
        } else if (window.history.length > 1) { // window.history.length > 1 判断进入该页面之前还有其它页面，登陆后则返回之前页面;
          window.history.back()
        } else {
          this.$routerGo(this, "replace", { path: '/' });
        }
      }
    },
    bindMobile(postData) {
      let $this = this;
      utilJs.postMethod(`${global.apiurl}members/bindMobile`, postData, function (res) {
        $this.isSubmit = true;
        localStorage.setItem("uMobile", $this.mobile);
        $this.bindGetIntegration();
        if ($this.userCount > 1) { // 若是该手机已有绑定账号，绑定成功后走合并流程
          $this.mobileLogin();
          return;
        }
        $this.$showCjToast({
          text: "绑定成功",
          type: "success",
        }).then(() => {
          $this.$store.commit("updateShowBindPhoneModal", {
            showBindPhoneModal: false
          });
          $this.goBack(res)
        });
      }, function () {
        $this.isSubmit = true;
      });
    },
    //平移平台找回账号用
    retrieveAccount(postData) {
      utilJs.postMethod(`${global.apiurl}members/newBindMobile`, postData, (res) => {
        let that = this;
        this.isSubmit = true;
        localStorage.setItem("uMobile", this.mobile);
        this.bindGetIntegration();
        this.$store.commit("updateShowBindPhoneModal", {
          showBindPhoneModal: false
        });
        if (res.account) {
          localStorage.setItem("accountList", JSON.stringify(res.account));
          let pp = that.$route.query.prevPath ? that.$route.query.prevPath : '';
          if (pp) {
            that.$routerGo(that, "push", { path: `/homePage/login/chooseAccount?code=${that.code}`, query: { prevPath: pp } });
          } else {
            that.$routerGo(that, "push", { path: `/homePage/login/chooseAccount?code=${that.code}` });
          }
        } else {
          this.$showCjToast({
            text: "绑定成功",
            type: "success",
          }).then(() => {
            let pp = that.$route.query.prevPath ? that.$route.query.prevPath : null;
            if (pp && !pp.includes('homePage/login/bindMobile')) {
              that.$routerGo(that, "replace", { path: pp });
            } else {
              that.$routerGo(that, "replace", { path: "/" });
            }
          })
        }
      }, failRes => {
        this.isSubmit = true;
      });
    },
    //获取个人所在地
    getInfo() {
      if (this.isNeedFillArea) { // 需要必填用户所在地
        var $this = this;
        utilJs.getMethod(global.apiurl + 'members', function (res) {
          if (res.provinceId != null && res.cityId != null && res.areaId != null) {
            $this.addrValue = ['' + res.provinceId, '' + res.cityId, '' + res.areaId]
          }
        });
      }
    },
    //分享
    wechatShare: function () {
      utilJs.wechatConfig("", "", "", "", function () { });
    },
    //手机端分享
    appShare: function () {
      utilJs.appShareTrue("", "", "", "");
    },
    linkToProtocol(url) {
      if (!url) return
      window.location.href = url;
    },
    getAppUseAndPrivacyProtocols() {
      utilJs.getMethod(`${global.apiurl}app/getAppUseAndPrivacyProtocols`, (res) => {
        this.isCheckAgreement = false;
        this.protocolInfo = res || null;
      });
    },
    getProtocol() {
      utilJs.getMethod(`${global.apiurl}protocols/getProtocolByProdType?prodType=-2`, (res) => {
        this.protocolInfo = res.protocol && res.protocol.length > 0 ? res.protocol : null;
        this.isCheckAgreement = res.relatesType == 1 ? true : false;
      });
    },
    getAreaListForAgent() {
      utilJs.getMethod(`${global.apiurl}common/getAreaListForAgent`, res => {
        this.addressData = res.data;
        if (!this.isLogin) {
          this.getInfo();
        }
      }, failRes => {});
    }
  },
  activated() {
    this.isLogin = this.$route.query.isLogin || 0;
    this.refereeId = this.$route.query.refereeId || '';
    this.mobile = this.$route.query.mobile || null;
    if (window.localStorage.getItem("isVisitor")) { // 游客模式
      this.isLogin = 1;
      this.refereeId = this.refereeId == '' || this.refereeId == undefined ? (localStorage.getItem("refereeId") || '') : this.refereeId;
    }
    this.$store.commit('updateLoadingStatus', {
      isLoading: false
    });
    //是否平移找回账号
    isRetrieve = this.$route.query.retrieve || 0;
    this.goodsRoomId = this.$route.query.goodsRoomId || 0;
    this.isiOS = navigator.userAgent.indexOf("IOSLogin") > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1;
    this.isAndroidApp = utilJs.isAndroidApp();
    this.isiOSApp = utilJs.isIOSAppALL();
    this.isClick = false;
    this.isSubmit = true;
    this.isAgree = 1;
    this.codeImgInfo = '';
    this.imgCode = '';
    this.loginStep = 1;
    this.fromChannel = !!navigator.userAgent.includes('aweme') ? 14 : 13;
    this.userCount = 0;
    this.userInfo = [];
    this.constUserInfo = [];
    this.currentUserIndex = -1;
    this.selectIndex = -1;
    this.destroyIndex = [];
    this.isClickCode = false;
    this.isAllWechat = false;
    this.isCheckAgreement = false;
    this.customUserInfo = [];
    this.isFillUserInfo = 0;
    this.enableAreaAgent = 0;
    this.enableXhAreaAgent = 0;
    this.isShowImgCode = false;
    let companyId = utilJs.getCompanyIdByHerf();
    // 已登录并且带isLogin则不需要再次用手机号登录,并且不是游客身份
    if (localStorage.getItem(localStorage.getItem(companyId) + "|token") && !!this.isLogin && !localStorage.getItem("isVisitor")) {
      this.$routerGo(this, "replace", {
        path: "/"
      });
      return;
    }
    //不是ios并且不是安卓app并且已绑定了手机号
    // if (!utilJs.isIOSAppALL() && !utilJs.isAndroidApp() && localStorage.getItem('uMobile')) {
    //   this.$routerGo(this, "replace", {
    //     path: "/member/menberInfo/changeMobile"
    //   });
    //   return;
    // }
    // 需要填写地址再请求接口
    if (localStorage.getItem(localStorage.getItem(companyId) + "|token") && (localStorage.getItem("locateType") == 1 || localStorage.getItem("locateType") == 2)) {
      this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
      // this.customUserInfo = (localStorage.getItem("customUserInfo") && JSON.parse(localStorage.getItem("customUserInfo"))) || [];
      // this.isFillUserInfo = localStorage.getItem("isFillUserInfo") || 0;
      this.enableAreaAgent = localStorage.getItem("enableAreaAgent") || 0;
      this.enableXhAreaAgent = localStorage.getItem("enableXhAreaAgent") || 0;
      this.enableWriteAddress = localStorage.getItem("enableWriteAddress") || 0;
      this.getAreaListForAgent()
    }
    this.customUserInfo = (localStorage.getItem("customUserInfo") && JSON.parse(localStorage.getItem("customUserInfo"))) || [];
    this.isFillUserInfo = localStorage.getItem("isFillUserInfo") || 0;
    if (this.isAndroidApp || this.isiOSApp) {
      this.getAppUseAndPrivacyProtocols();
    } else {
      this.getProtocol();
    }
    if (isRetrieve == 0) {
      setDocumentTitle(!!this.isLogin ? '登录' : "绑定手机");
    } else {
      setTimeout(() => {
        setDocumentTitle("绑定手机");
      }, 600);
    }
    this.wechatShare();
  },
  deactivated() {
    this.num = 60;
    clearInterval(this.interval);
    this.yzText = "获取验证码";
    this.isYz = true;
    this.mobile = null;
    this.code = null; // 验证码
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.vux-cell-box:not(:first-child):before {
  border-top: none !important;
}
.bind-head {
  background-color: #f7dfb0;
  color: #6e442d;
}
.basic-title::before {
  content: "";
  position: absolute;
  width: 20%;
  height: 1px;
  top: 50%;
  background-image: linear-gradient(
    to right,
    rgba(var(--colorRGB), 0.1),
    rgba(var(--colorRGB), 1)
  );
  left: 15%;
}
.basic-title::after {
  content: "";
  position: absolute;
  width: 20%;
  height: 1px;
  top: 50%;
  background-image: linear-gradient(
    to left,
    rgba(var(--colorRGB), 0.1),
    rgba(var(--colorRGB), 1)
  );
  right: 15%;
}
.destroy-icon{
  background: rgba(244, 98, 98, 0.1);
  border-radius: 4px;
  color: #F46262;
}
</style>
